<?php

/**
 * 生活服务分类后台管理
 * @copyright (c) 2013, Alvin
 * 
 */
class ServiceCatAction extends AdminAction {

    public function _initialize() {
        parent::_initialize();
    }

    public function edit() {
        if (IS_POST) {
            if (!$_POST['title']) {
                $this->error('名称不能为空');
            }
            foreach ($_POST as $pk => $pv){
                $_POST[$pk] = t(trim($pv));
            }
            if ($_POST['cat_id'] == 0)
                $res = M('ServiceCat')->add($_POST);
            else
                $res = M('ServiceCat')->save($_POST);
            if ($res) {
                $this->success('操作成功');
            } else {
                $this->success('操作失败');
            }
        } else {
            $id   = (int) $this->_get("id");
            $data = M('ServiceCat')->find($id);
            $this->assign('data', $data);
            $this->display();
        }
    }

    public function delete() {
        $id = (int) $this->_get("id");
        if (M('ServiceCat')->delete($id)) {
            $this->success("删除成功！");
        } else {
            $this->error("删除失败！");
        }
    }

}

?>
